package com.projectName.www.service;

import com.projectName.www.dao.*;
import com.projectName.www.po.Dish;
import com.projectName.www.po.Order;
import com.projectName.www.po.User;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements UserService {
    UserDaoImpl userDaoImplement =null;
    DishDaoImpl dishDaoImplement = null;
    OrderDaoImpl orderDaoImplement = null;

    /**
     * 通过用户名寻找用户
     * @param username
     * @return
     */
    @Override
    public User queryByUsername(String username) {
        User user = new User();
        userDaoImplement = new UserDaoImpl();
        user = userDaoImplement.queryByUsername(username);
        return user;
    }

    @Override
    public List<User> findUserByName(String userName) {
        userDaoImplement=new UserDaoImpl();
        return userDaoImplement.findUserByName(userName);
    }

    @Override
    public List<Dish> findDishByName(String dishName) {
        dishDaoImplement=new DishDaoImpl();
        return dishDaoImplement.findDishByName(dishName);
    }

    //账号封禁login方法

    @Override
    public void insert(User user) {
        //把得到的user对象传入数据库（user中只有姓名，id，密码）
        userDaoImplement =new UserDaoImpl();

        userDaoImplement.insert(user);
    }

    //寻找所有用户
    @Override
    public List<User> findall() {
        List<User> userList=new ArrayList<>();
        userDaoImplement = new UserDaoImpl();
        userList=userDaoImplement.findall();
        return userList;
    }

    @Override
    public User findByID(String id) {


        User user=null;
        userDaoImplement = new UserDaoImpl();
        user=userDaoImplement.findByID(id);
        return user;
    }

    @Override
    public void delete(String uid) {
        userDaoImplement =new UserDaoImpl();
        userDaoImplement.delete(uid);

    }

    @Override
    public List<Dish> findAllDishs() {
        DishDao dd=new DishDaoImpl();
        return dd.findall();

    }

    /**
     * 用户和管理员都有
     * @param uid
     * @return  寻找商家下的全部菜品并返回
     */
    @Override
    public List<Dish> findDishBySlr(String uid) {
        DishDao dd=new DishDaoImpl();
        return dd.findBySlr(uid);
    }

    //显示所有商家
    @Override
    public List<User> findSlr() {
        UserDao userDao=new UserDaoImpl();
        return userDao.findSlr();
    }

    @Override
    public void updateUser(User user) {
        userDaoImplement=new UserDaoImpl();
        userDaoImplement.update(user);
    }

    @Override
    public void updateDish(Dish dish) {
        dishDaoImplement=new DishDaoImpl();
        dishDaoImplement.update(dish);
    }

    //请注意，不能让用户修改总价
    @Override
    public void updateOrder(Order order) {
        orderDaoImplement=new OrderDaoImpl();
        orderDaoImplement.update(order);
    }

    @Override
    public void addMoney(String uid, BigDecimal admoney) {
        userDaoImplement=new UserDaoImpl();
        userDaoImplement.addMoney(uid,admoney);
    }

    @Override
    public BigDecimal showMoney(String uid) {
        userDaoImplement=new UserDaoImpl();
        return userDaoImplement.getMoney(uid);
    }

    @Override
    public List<Order> findAllOrder() {
        OrderDao orderDao=new OrderDaoImpl();
        return orderDao.findall();
    }

    //显示所有订单

    //查看该菜品的所有评价
    public List<String> showRemark(String did){

        RemarkDao rd=new RemarkDaoImpl();
        return rd.queryRemarkBydid(did);
    }

    //给菜品评价,记得判断一下传进来的是商家喔，不是就寄
    public void setRemark(String did,String rmk){

        RemarkDao rd=new RemarkDaoImpl();
        rd.setRemark(did,rmk);
    }

    public List<String> setComplaints(String uid){
        return null;
    }
    public void setComplaints(String uid,String cmp){

    }
    @Override
    public List<Order>findByCtm(String Uid){
        OrderDao od=new OrderDaoImpl();
        List<Order> orderByCtm = od.findOrderByCtm(Uid);
        return orderByCtm;
    }

    ////通过商家来找订单
    @Override
    public List<Order>findBySlr(String Uid){
        OrderDao od=new OrderDaoImpl();
        List<Order> orderBySlr = od.findOrderBySlr(Uid);
        return orderBySlr;
    }





}
